package graphics.raytracing.shaders;

import java.util.HashMap;
import java.util.Map;

import graphics.datastructures.Triangle;
import graphics.raytracing.CastResult;
import graphics.raytracing.Shader;

public class RandomColorShader implements Shader<Triangle>{
	private Map<Triangle, float[]> colormap = new HashMap<>();
	@Override
	public float[] shade(CastResult<Triangle> result) {
		if(result == null)
			return ar(0,0,0);
		Triangle t = result.getTracable();
		if(colormap.containsKey(t))
			return colormap.get(t);
		else
			return put(colormap,t,randomcolor());
	}
	private float[] put(Map<Triangle, float[]> map, Triangle t, float[] randomcolor) {
		map.put(t, randomcolor);
		return randomcolor;
	}
	private float r(){return (float) Math.random();}
	private float[] ar(float...f){return f;}
	private float[] randomcolor() {
		return ar(r(),r(),r());
	}

}
